
package cn.cloud.all.security.oauth2.provider.expression;

import cn.cloud.all.security.core.Authentication;
import cn.cloud.all.security.web.FilterInvocation;
import cn.cloud.all.security.web.access.expression.DefaultWebSecurityExpressionHandler;
import org.springframework.expression.spel.support.StandardEvaluationContext;

public class OAuth2WebSecurityExpressionHandler extends DefaultWebSecurityExpressionHandler {

    public OAuth2WebSecurityExpressionHandler() {
        setExpressionParser(new OAuth2ExpressionParser(getExpressionParser()));
    }

    @Override
    protected StandardEvaluationContext createEvaluationContextInternal(Authentication authentication, FilterInvocation invocation) {
        StandardEvaluationContext ec = super.createEvaluationContextInternal(authentication, invocation);
        ec.setVariable("oauth2", new OAuth2SecurityExpressionMethods(authentication));
        return ec;
    }
}